﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Evaluation3.utils;

public partial class Render : System.Web.UI.Page
{
    httpUtils objUtils = new httpUtils();  
    protected void Page_Load(object sender, EventArgs e)
    {
        string sURL = Request.Url.ToString().ToLower();
        if (sURL.EndsWith(".aspx"))
        {
            return;
        }
        main.Controls.Add(objUtils.LoadModule("mod"));
        //holder1.Controls.Add(CreatePanel("Add Panel 1"));
        
        //holder2.Controls.Add(CreatePanel("Add Panel 2"));        

    }

    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);

        //UserControl uc = (UserControl)LoadControl(@"~\uicontrol\companyInfoControl.ascx");
        //uc.FindControl("dyna").Controls.Add(CreatePanel("Panel 1"));
        //uc.ID = "addpanel";
        //holder2.Controls.Add(uc);
    }
    //method này có chức năng tương tự như thằng OnInit ở trên
    void Page_Init()
    {
        //HtmlGenericControl hg = new HtmlGenericControl("asp:Panel");
        //Control ctr = new Control();
        //ctr.Controls.Add(CreatePanel("Panel 1"));
        //hg.Controls.Add(ctr);

        //holder1.Controls.Add(CreatePanel("Panel 1"));

        //UserControl uc = (UserControl)LoadControl(@"~\uicontrol\companyInfoControl.ascx");
        //uc.FindControl("dyna").Controls.Add(CreatePanel("Panel 1"));
        //uc.ID = "addpanel";
        //holder2.Controls.Add(uc);

        LoadUC("Panel Add on Init <br>");
    }
    protected void LoadUC(String s)
    {
        UserControl uc = (UserControl)LoadControl(@"~\uicontrol\companyInfoControl.ascx");
        uc.FindControl("dyna").Controls.Add(CreatePanel(s));
        uc.ID = "addpanel";
        holder2.Controls.Add(uc);
    }
    protected Panel CreatePanel(String s)
    {
        Panel pnl = new Panel();
        pnl.BackColor = System.Drawing.Color.Green;
        Label lbltext = new Label();
        Button btn = new Button();
        btn.Text = "Click me";
        btn.Click += new EventHandler(btn_Click);
        lbltext.Text = s;
        lbltext.ForeColor = System.Drawing.Color.White;
        pnl.Controls.Add(lbltext);
        pnl.Controls.Add(btn);
        return pnl;
    }

    protected void btn_Click(Object sender, EventArgs e)
    {
        holder2.Controls.Clear();
        LoadUC("You have Clicked Button ! <br>");
    }
}
